//
//  YGKSMSVertificationController.m
//  PathTrack
//
//  Created by Jay on 16/7/11.
//  Copyright © 2016年 YGK. All rights reserved.
//

#import "YGKSMSVertificationController.h"

@interface YGKSMSVertificationController ()

@property (weak, nonatomic) IBOutlet UITextField *phoneNum_text;

@property (weak, nonatomic) IBOutlet UITextField *vertification_text;

@end

@implementation YGKSMSVertificationController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (IBAction)back:(id)sender {
    NSLog(@"back");
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}

- (IBAction)getVertificationMethod:(id)sender {
    NSLog(@"get vertification");
    
    /**
     *  @from                    v1.1.1
     *  @brief                   获取验证码(Get verification code)
     *
     *  @param method            获取验证码的方法(The method of getting verificationCode)
     *  @param phoneNumber       电话号码(The phone number)
     *  @param zone              区域号，不要加"+"号(Area code)
     *  @param customIdentifier  自定义短信模板标识 该标识需从官网http://www.mob.com上申请，审核通过后获得。(Custom model of SMS.  The identifier can get it  from http://www.mob.com  when the application had approved)
     *  @param result            请求结果回调(Results of the request)
     */
    
    [SMSSDK getVerificationCodeByMethod:SMSGetCodeMethodSMS phoneNumber:self.phoneNum_text.text
                                   zone:@"86"
                       customIdentifier:nil
                                 result:^(NSError *error){
                                     if (!error) {
                                         NSLog(@"获取验证码成功");
                                         [MBProgressHUD showSuccess:@"获取验证码成功" toView:self.view];

                                     } else {
                                         NSLog(@"错误信息：%@",error);
                                         [MBProgressHUD showError:error.userInfo[@"getVerificationCode"] toView:self.view];
                                         
                                     }}];

}

- (IBAction)registerMethod:(id)sender {
    [SMSSDK commitVerificationCode:self.vertification_text.text
                       phoneNumber:self.phoneNum_text.text
                              zone:@"86"
                            result:^(NSError *error) {
        
        if (!error) {
            NSLog(@"验证成功");
            [MBProgressHUD showSuccess:@"验证成功" toView:self.view];
        }else{
            NSLog(@"错误信息:%@",error);
            [MBProgressHUD showError:error.userInfo[@"commitVerificationCode"] toView:self.view];
        }
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
